package offer;

public class IsSymmetric {
    class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public boolean isSymmetric(TreeNode root) {
        if (root == null) {
            return true;
        } else {
            return recur(root.left, root.right);
        }
    }

    public boolean recur(TreeNode L, TreeNode R) {
        if (L == null && R == null) {
            return true;
        } else if (L == null && R != null) {
            return false;
        } else if (L != null && R == null) {
            return false;
        }
        if (L.val == R.val) {
            return recur(L.left, R.right) && recur(L.right, R.left);
        } else {
            return false;
        }
    }
}
